import { mergeOptions } from "./utils"

// mixin 存放的位置在Vue.options, 要变成的结构为 { created: [fn, fn, fn] }
export function initGlobalApi(Vue) {
  Vue.options = {
    _base: Vue // 创建组件节点的时候会用到 createComponentNode
  }
  Vue.mixin = function (mixin) {
    this.options = mergeOptions(this.options, mixin)
  }

  Vue.extend = function (options) {
    function Sub(options = {}) {
      this._init(options)
    }
    Sub.prototype = Object.create(Vue.prototype)
    Sub.prototype.constructor = Sub
    Sub.options = mergeOptions(Vue.options, options)
    return Sub
  }

  // 全局组件存放位置
  Vue.options.components = {}
  Vue.component = function (id, definition) {
    definition = typeof definition === "function" ? definition : Vue.extend(definition)
    Vue.options.components[id] = definition
  }
}
